 # -*- coding: utf8 -*-

import socket
import struct
import select

if __name__ == "__main__":
    tmp = ""
    for n in range(1, 1000):
        tmp += "sadfasdfasd"
    big_data = tmp.encode("utf-8")
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 1024*1024*5)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack('hh', 1, 3))
    ret = sock.getsockopt(socket.SOL_SOCKET, socket.SO_LINGER,12)
    print("SO_LINGER: ", ret)
    #sock.connect(("10.212.34.117", 12351))
    sock.connect(("10.212.34.117", 12351))
    #sock.send("1".encode("utf-8"))
    #sock.shutdown(socket.SHUT_RD)
    #sock.setblocking(True)
    #r = sock.recv(24)
    #sock.shutdown(socket.SHUT_RD) # 对端如果继续发数据会触发关闭
    #sock.setblocking(False)
    sock.send("1".encode("utf-8"))
    #sock.send("111111111111111111111111111111".encode("utf-8"))
    sock.setblocking(False)
    #sock.send(big_data)
    #sock.shutdown(socket.SHUT_WR)
    #sock.close()
    #sock.close()
    while True:
        r = [sock]
        w = [sock]
        x = [sock]
        rr, rw, rx = select.select(r, w, x, 6000)
        if rx:
            print(rx)
        if rr:
            data_recv = sock.recv(10)
            print("len: ", len(data_recv))
            if data_recv:
                print("recv: ", str(data_recv))